package com.cn.jinl.controller;


import com.cn.jinl.api.ILinePeiService;
import com.cn.jinl.domain.LinePei;
import com.cn.jinl.domain.LinePeiAttr;
import com.cn.jinl.domain.LinePeiBan;
import com.cn.jinl.domain.LinePeiOut;
import com.cn.jinl.utils.CommonUtil;
import com.cn.jinl.utils.JsonResponse;
import com.cn.jinl.utils.QueryForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/linepei")
public class LinePeiController {

    @Autowired
    private ILinePeiService linePeiService;

    @RequestMapping("/getLinePeiListMap/{frontToken}")
    @ResponseBody
    public JsonResponse<Map<String,Object>> getLinePeiListMap(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<Map<String,Object>> response = new JsonResponse<Map<String,Object>>();
        Map<String,Object> maps  = linePeiService.getLinePeiListMap(queryForm);
        response.setResult(maps);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/getLinePeiAttrs/{frontToken}")
    @ResponseBody
    public JsonResponse<List<LinePeiAttr> > getLinePeiAttrs(String peiId, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<LinePeiAttr> > response = new JsonResponse<List<LinePeiAttr> >();
        List<LinePeiAttr> lists = linePeiService.getLinePeiAttrs(peiId);
        response.setResult(lists);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/getLinePeiBans/{frontToken}")
    @ResponseBody
    public JsonResponse<List<LinePeiBan> > getLinePeiBans(String peiId, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<LinePeiBan> > response = new JsonResponse<List<LinePeiBan> >();
        List<LinePeiBan> lists = linePeiService.getLinePeiBans(peiId);
        response.setResult(lists);
        response.setSuccess(true);
        return  response;
    }

    @RequestMapping("/getLinePeiOuts/{frontToken}")
    @ResponseBody
    public JsonResponse<List<LinePeiOut> > getLinePeiOuts(String peiId, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<LinePeiOut> > response = new JsonResponse<List<LinePeiOut> >();
        List<LinePeiOut> lists = linePeiService.getLinePeiOuts(peiId);
        response.setResult(lists);
        response.setSuccess(true);
        return  response;
    }


    @RequestMapping("/getLinePeiLists/{frontToken}")
    @ResponseBody
    public JsonResponse<List<LinePei> > getLinePeiLists(QueryForm queryForm, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<List<LinePei> > response = new JsonResponse<List<LinePei> >();
        List<LinePei> lists = linePeiService.getLinePeiLists(queryForm);
        response.setResult(lists);
        response.setSuccess(true);
        return  response;
    }


    @ResponseBody
    @RequestMapping("/updateLinePei/{frontToken}")
    public JsonResponse<String> updateLinePei(@RequestBody LinePei linePei, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = linePeiService.updateLinePei(linePei);
        return CommonUtil.getResponseData(response,result);
    }

    @ResponseBody
    @RequestMapping("/addLinePeiOut/{frontToken}")
    public JsonResponse<String> addLinePeiOut(LinePeiOut linePeiOut, @PathVariable(value = "frontToken",required = true) String frontToken) throws Exception {
        JsonResponse<String> response = new JsonResponse<String>();
        String result = linePeiService.addLinePeiOut(linePeiOut);
        return CommonUtil.getResponseData(response,result);
    }
}
